home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: I need help on putting 2 strings together into 1(concatenate)
- Date: 20 Feb 1996 23:32:35 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Feb20163235@qcd.lanl.gov>
- References: <4gcr1b$ft3@cloner4.netcom.com>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: spdcool@ix.netcom.com's message of 20 Feb 1996 15:57:31 GMT
-
- In article <4gcr1b$ft3@cloner4.netcom.com> spdcool@ix.netcom.com(SPD)
- writes:
- <snip>
- struct data {
- char *full_name;
- int age;
- float salary;
- };
-
- struct name {
- char *first1, *last1;
- };
- <snip>
- struct name fname[3], lname[3];
- struct data secret[5];
- <snip>
- fname[o].first1 = "Joe";
-
- That o is presumably 0. So, your fname[0].first1 points to a region of
- unmodifiable memory 4 characters long containing the characters 'J'
- 'o' 'e' and '\0'.
-
- <snip>
- lname[0].last1 = "Jordan";
-
- I guess you known what this means now.
-
- <snip>
- secret[i].full_name = fname[e].first1;/* the trouble some part begin
-
- I hope the comment actually ends. So secret[i].full_name points to the
- same place as fname[e].first1, which if e is 0 means "a region of
- unmodifiable memory 4 characters long containing the characters 'J'
- 'o' 'e' and '\0'".
-
- <snip>
- strcat(secret[i].full_name," ");
-
- This means find the first '\0' in what secret[i].full_name points to,
- overwrite that with ' ' and overwrite the next location with '\0'.
-
- Ooops! it was pointing to a region which was unmodifiable, and there
- was no location reserved for it beyond the '\0'. Disaster!
-
- <snip>
- please e-mail me at spdcool@ix.netcom.com and spd7398@acf4.nyu.edu
- mail me at both places b/c I may be at home or in school
-
- Please read the answer here.
-
- I leave it as an excercise to figure out how to correct it. With what
- I told you, the faq, the routines malloc and strlen, you should be
- able to do the rest?
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-